<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>帮助文档管理</title>
	<%@ include file="/view/common/tags.jsp"%>
	<script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
</head>
<body>
	<section class="content">
    	<div class="row">
            <div class="col-md-12">
                <div class="box">
                	<div class="box-body">
						<div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="" method="post" id="dataForm">
                                	<div class="searchMenu">
                                		 <div>
                                		    <label style="width:120px;">文档类型：</label>
                                            <sk:select cssClass="form-control select" name="wm[DOCUMENT_TYPE]" id="documentType" value="${page.wm.DOCUMENT_TYPE}">
                                            	<option value="">请选择</option>
												<option value="10">注册协议</option>
												<option value="20">订单协议</option>
                                            </sk:select>
                                        </div>
                                        <div>
                                            <label>操作时间：</label>
                                            <input id="createTimeStart" name="wm[_MORE_EQUAL$OPT_TIME]" value="${page.wm._MORE_EQUAL$OPT_TIME}"  type="text"  class="Wdate" 
											  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 00:00:00',alwaysUseStartDate:true,maxDate:'#F{$dp.$D(\'createTimeEnd\')}',minDate:'#F{$dp.$D(\'createTimeEnd\',{d:-30,H:-23,m:-59,s:-59})}'})" /> 
											  <span class="pull-left">&nbsp;-&nbsp;</span>
											  <input id="createTimeEnd" name="wm[_LESS_EQUAL$OPT_TIME]" value="${page.wm._LESS_EQUAL$OPT_TIME}"  class="Wdate" 
								               onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 23:59:59',alwaysUseStartDate:true,minDate:'#F{$dp.$D(\'createTimeStart\')}',maxDate:'#F{$dp.$D(\'createTimeStart\',{d:+30,H:+23,m:+59,s:+59})}'})" />
                                        </div>
                                        <div class="mal10" >
                                            <button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>
                                            <sk:button type="button"  rightKey="20170816153357"  _class="btn btn-success btn-sm"  onclick="add()"><span class='glyphicon glyphicon-plus'></span>添&nbsp;加</sk:button>
                                        </div>
                                	</div>
                                </form>
                        	</div>
						</div>
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                            <thead>
                            	<tr>
                                	<th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false">序号</th>
                                	<th data-field="documentType" data-align="center" data-formatter="documentTypeFormatter" data-sortable="true">文档类型</th>
                                	<th data-field="documentTitle" data-align="center" data-sortable="true" >文档标题</th>
                                	<th data-field="orderByNo" data-align="center" data-sortable="true">排序号</th>
                                	<th data-field="openFlag" data-align="center" data-formatter="openFlagFormatter" data-sortable="true">开启状态</th>
                                    <th data-field="optAccount" data-align="center" data-sortable="true">操作人帐号</th>
                                    <th data-field="optTime" data-align="center" data-formatter="timeFormatter_point" data-sortable="true">操作时间</th>
                                    <th data-field="deleteButton" data-align="center"  data-formatter="buttonFormatter" data-sortable="false">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
       	</div>
	</section>
<%@ include file="/view/common/footer.jsp"%>
</body>
<script>
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if (msgg && msgg!=null && msgg!='null') { 
	  layer.msg(msgg);
}
var tableIndex = 0; // 添加修改的弹出框的ID
var documentType = "";

//加载table 数据
$(function(){
   $("#dataTable").bootstrapTable({
       url: "${sysManagerV1}/pubgBaseHelpDocument/data.json",
       method:"get", 
       pagination:true,
       sidePagination:"server",
       queryParams: function(params) {
           return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
       }
   }); 

})

//查询
function findData(){
$("#dataTable").bootstrapTable("refresh",{} ); 
}

/*bootstrap table点击行事件*/
$(function(){
  $("body").on("click","table>tbody>tr",function(){
   $(this).css("background","#e1ecf1").siblings().css("background","");
});
})

//文档类型
function documentTypeFormatter(value, row) {
    var html = "";
    $("#documentType option").each(function(){  //遍历所有option  
       var value = $(this).val();   //获取option值   
       if(value == row.documentType){
    	   html = "<span>" + $(this).text() + "</span>"; 
       }  
   })  
   return html;
}

//启用状态
function openFlagFormatter(value, row) {
   var html = "";
   if (row.openFlag == 1) {
       html = "<span class='text-success'>启用 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
       html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.documentTitle+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-stop'></span>停用</button>";
   }else {
       html = "<span class='text-warning'>停用 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
       html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.documentTitle+"\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-ok'></span>发布</button>";
   }
   return html;
}

//操作按钮
function buttonFormatter(value, row, index) {
 var caozuo3 = "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+", "+row.openFlag+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
 var caozuo2 = "<button id='btn_edit' type='button' onclick='_update("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修 改</button>";
 return caozuo2 + caozuo3;
}

//弹出添加的窗口
function add(){
 tableIndex = layer.open({
     type: 2,
     title: "添加帮助文档",
     closeBtn: 1,
     shadeClose: true,
     area: ['660px', '620px'],
     content: "${sysManagerV1}/baseHelpDoc/toAddBaseHelpDoc?rowId=0",
     btn: ["确 认","关 闭"], 
     yes: function(index, layero){
         var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
         iframeWin.add();
     }
 });
}

//弹出添加的窗口      修改功能
function _update(rowId){
 tableIndex = layer.open({
     type: 2,
     title: "修改帮助文档",
     closeBtn: 1,
     shadeClose: true,
     area: ['660px', '620px'],
     content: "${sysManagerV1}/baseHelpDoc/toAddBaseHelpDoc?rowId=" + rowId,
     btn: ["确 认","关 闭"], 
     yes: function(index, layero){
         var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
         iframeWin.add();
     }
 });
}

//停用（启用）
function _stop(rowId, openFlag, documentTitle){
 var descStr = '【停用】<span style="color:red">' + documentTitle +"</span>";
 if (openFlag == 0) {
     descStr = '【启用】<span style="color:red">' + documentTitle +"</span>";
 }
 openFlag = Math.abs(Number(openFlag) - 1);
 layer.confirm('您确认'+descStr+'吗？', {btn: ['确认', '取消']},
 function(){
     if (rowId == null || rowId == "") {
         layer.msg("id不能为空!");
         return;
     }
     
     $.ajax({
         url: "${sysManagerV1}/pubgBaseHelpDocument/updateOpenFlag",
         type: "post",
         cache: false,
         data: {rowId:rowId, openFlag:openFlag},
         dataType:"json",
         async:false,
         success: function(data) {
             if (data == 1) { 
                 layer.msg(descStr+"成功", {icon: 1});
                 findData();
             } else if(data == "-2"){
                 window.location.href="/";
             } else {
                 layer.msg(descStr+"失败", {icon: 5});
             }
         },
         error: function(err){
             alert(JSON.stringify(err));
         }
     });
 });
}

//删除帮助文档
function deleteEmp(rowId, openFlag){
 layer.confirm("您确认【删除】?", {btn: ['确认', '取消']},
 function(){
     $.ajax({
         url: "${sysManagerV1}/pubgBaseHelpDocument/delete",
         type: "post",
         cache: false,
         data: {rowId:rowId, openFlag:openFlag},
         dataType:"json",
         async:false,
         success: function(data) {
             if (data == 1) { 
                 layer.msg("删除成功", {icon: 1});
                 findData();
             } else if (data == 3) {
                 layer.msg("删除失败，该帮助文档启用中");
             } else if(data == "-2"){
                 window.location.href="/";
             } else {
                 layer.msg(data, {icon: 5});
             }
         }
     });
 });
}
</script>
</html>